﻿using Bankomat.Business;
using Bankomat.States.AbstractStates;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bankomat.States.Strings.hu;

namespace Bankomat.States
{
    public class WithDrawState : ActionState
    {
        public WithDrawState()
        {
            myOptionLeft1 = Resource.WithDrawStateLeft1;
            myOptionLeft2 = Resource.WithDrawStateLeft2;
            myOptionLeft3 = Resource.WithDrawStateLeft3;
            myOptionLeft4 = Resource.WithDrawStateLeft4;

            myOptionRight1 = Resource.WithDrawStateRight1;
            myOptionRight2 = Resource.WithDrawStateRight2;
            myOptionRight4 = Resource.BackMessage;
        }

        public override State OptionLeft1Selected()
        {
            return CheckWithdrawIsSuccess(1000);
        }

        public override State OptionLeft2Selected()
        {
            return CheckWithdrawIsSuccess(5000);
        }

        public override State OptionLeft3Selected()
        {
            return CheckWithdrawIsSuccess(10000);
        }

        public override State OptionLeft4Selected()
        {
            return CheckWithdrawIsSuccess(25000);
        }

        public override State OptionRight1Selected()
        {
            return CheckWithdrawIsSuccess(50000);
        }

        public override State OptionRight2Selected()
        {
            return CheckWithdrawIsSuccess(100000);
        }

        public override State CancelSelected()
        {
            return new MainMenuState();
        }

        public override State CardReaderSelected()
        {
            return new InitialState();
        }

        private State CheckWithdrawIsSuccess(int sum)
        {
            var result = myOperationManager.Withdraw(sum);

            if (result.ResultEnum == WithDrawResultEnum.UnSuccess)
            {
                return new UnSuccesState();
            }
            else if (result.ResultEnum == WithDrawResultEnum.EmptyCasette)
            {
                return new EmptyCasettesState();
            }
            else
            {
                return new SuccessState();
            }
        }
    }
}
